//
//  DuDaoLeftMenuController.m
//  KIASupervisory
//
//  Created by tan_xin on 14-7-1.
//  Copyright (c) 2014年 MyCompany. All rights reserved.
//

#import "DuDaoLeftMenuController.h"

#import "DDErandsApplyListViewController.h"
#import "DDErandChangeListViewController.h"
#import "DDEAddProblemViewController.h"
#import "EditPasswordViewController.h"
#import "FeedbackViewController.h"
#import "AboutUsViewController.h"
#import "HistoryProblemListViewController.h"
#import "HistoryApplySearchViewController.h"
#import "SurveyViewController.h"

@interface DuDaoLeftMenuController ()

@property (weak, nonatomic) IBOutlet UIImageView *iconImgV;
@property (weak, nonatomic) IBOutlet UILabel *nameLbl;
@property (weak, nonatomic) IBOutlet UITableView *menuTable;
@property (weak, nonatomic) IBOutlet UIButton *logoutBtn;

@property (nonatomic, strong) NSArray *iconList;
@property (nonatomic, strong) NSArray *titleList;

- (IBAction)logoutAction:(id)sender;

@end

@implementation DuDaoLeftMenuController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    
    if (iPhone5) {
        self.menuTable.scrollEnabled = NO;
    } else {
        self.menuTable.scrollEnabled = YES;
    }
    
    self.iconList = [[NSArray alloc] initWithObjects:
                     @"icon_出差申请.png",@"icon_出差变更申请.png",@"icon_历史问题查看.png",@"icon_历史问题查看.png",
                     @"icon_问卷调查.png",@"icon_修改密码.png",@"icon_关于我们.png", nil];
    self.titleList = [[NSArray alloc] initWithObjects:@"出差申请",@"出差变更申请",@"历史问题查看",@"历史出差查询",
                      @"问卷调查",@"修改密码",@"关于我们", nil];
    
    UserInfo *user = [UserInfo instance];
    NSString *name = [user.info objectForKeyOrNil:@"xm"];
    self.nameLbl.text = name;
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

#pragma mark - IBAction methods
- (IBAction)logoutAction:(id)sender {
    AppDelegate *dele = [AppDelegate sharedDelegate];
    [dele.ddLeftMenu dismissViewControllerAnimated:YES completion:NULL];
}

#pragma mark - UITableViewDataSource methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 7;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellIdentifier = @"DDMenuCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        cell.backgroundColor = [UIColor clearColor];
    }
    
    UIImageView *iconImgV = (UIImageView *)[cell.contentView viewWithTag:100];
    UILabel *titleLbl = (UILabel *)[cell.contentView viewWithTag:101];
    
    NSInteger row = indexPath.row;
    if ([self.iconList count] > row) {
        NSString *iconImgName = [self.iconList objectAtIndex:row];
        NSString *titleName = [self.titleList objectAtIndex:row];
        
        iconImgV.image = [UIImage imageNamed:iconImgName];
        titleLbl.text = titleName;
    }
    
    return cell;
    
}

#pragma mark - UITableViewDelegate methods
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return 44.0;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    NSInteger row = indexPath.row;
    AppDelegate *dele = [AppDelegate sharedDelegate];
    DDMenuController *leftMenu = dele.ddLeftMenu;
    
    SuperViewController *controller = nil;
    switch (row) {
        case 0: {
            controller = (DDErandsApplyListViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"ErrandsApplyList"];
            break;
        }
        case 1: {
            controller = (DDErandChangeListViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"DDErandChangeList"];
            break;
        }
        case 2: { //历史问题查看
            controller = (HistoryProblemListViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"HistoryProblemList"];
            break;
        }
        case 3: { //历史出差查询
            controller = (HistoryApplySearchViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"HistoryApplySearch"];
            break;
        }
        case 4: { //问卷调查
            controller = (SurveyViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"SurveyView"];
            break;
            break;
        }
        case 5: { //修改密码
            controller = (EditPasswordViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"EditPassword"];
            break;
        }
//        case 6: { //问题反馈
//            controller = (FeedbackViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"FeedBack"];
//            break;
//        }
        case 6: { //关于我们
            controller = (AboutUsViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"AboutUs"];
        }
            
        default:
            break;
    }
    
    if (controller != nil) {
        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
        [leftMenu setRootController:navController animated:YES];
    }
}

@end
